import { Body, Controller, Get, Post } from '@nestjs/common';
import { PrismaService } from 'src/modules/prisma.service';
import { MessageService } from './message.service';
import { filterUndefined } from 'src/utils';

@Controller('message')
export class MessageController {
  constructor(
    private readonly mysql: PrismaService,
    private readonly messageService: MessageService
  ) {}

  @Post('page-messages')
  async findPageMessage(@Body() data: any,) {
    const userList = await this.mysql.message.findMany({
      where: {
        isDeleted: false,
        type: {
          equals: data.type,
        },
      },
      take: Number(data.pageSize || 10),
      skip: (Number(data.current || 1) - 1 ) * Number(data.pageSize || 10),
    });
    const totalCount = await this.mysql.user.count({
      where: {
        isDeleted: false,
      },
    });

    return {
      list: userList,
      pageSize: Number(data.pageSize || 10),
      currentPage: Number(data.currentPage || 1),
      totalCount,
    };
  }

}
